function [r,rBuy,rSell] = rollingAR(price_path,size)
r = log(price_path(2:end)./price_path(1:end-1));

forecastValue = NaN(length(price_path)-1,1);
rBuy = NaN(length(price_path),1);
rSell = NaN(length(price_path),1);
    
model = arima(1,0,0); %model AR(1)

for i=size+1:length(price_path)
    fit = estimate(model,r(i-size:i-1));
    [forecastValue(i) ~] = forecast(fit,1,'Y0',r(i-size:i-1));
if(forecastValue(i)>=0)
        rBuy(i) = log(price_path(i)/price_path(i-1));
end 
if(forecastValue(i)<0)
        rSell(i) = log(price_path(i)/price_path(i-1));
end
end

% close all
hold on
plot(forecastValue,'blue');
plot(r,'red');
